package com.kuaimacode.kframework.api.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.IService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.kuaimacode.kframework.mybatis.mapper.agent.SysAgentMapper;
import com.kuaimacode.kframework.mybatis.models.agent.SysAgent;
import com.kuaimacode.kframework.mybatis.models.user.User;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * <p>
 * 分站信息表
 服务类
 * </p>
 *
 * @author Bean
 * @since 2019-03-13
 */
@Service
public class AgentService extends ServiceImpl<SysAgentMapper, SysAgent> {

    /**
     * 根据行政区划代码获取分站信息
     * @param id
     * @return
     */
    public SysAgent getAgentInfoById(String id){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("stat","0");
        wrapper.eq("id",id);
        return baseMapper.selectOne(wrapper);
    }

    /**
     *获取分站信息
     * @param id
     * @return
     */
    public List<SysAgent> getInfoByAgentId(String agentId){
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("stat","0");
        wrapper.eq("id",agentId);
        return baseMapper.selectList(wrapper);
    }

    public int updateBalance(String agentId, String inOut, BigDecimal amount){

        return baseMapper.updateBalance(agentId,inOut,amount);
    }

    /**
     * 分站是否开通
     * @param id
     * @return
     */
	public boolean isOpened(String id) {
        SysAgent agent = baseMapper.selectById(id);
        return agent != null && agent.getStat() == 0;
    }
}
